import json

from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from pymysql.converters import escape_string

from SQL_CRUD_Interface.CRUD import update_interface


@csrf_exempt
def update_chinese(request):
    if request.method == "POST":
        data = json.loads(request.body)
        english = data.get("english")
        chinese = data.get("chinese")

        sql = '  UPDATE `tb_word` SET `chinese`="%s"   WHERE `english`="%s"    ' % (escape_string(chinese), escape_string(english))
        aaa = update_interface("127.0.0.1", "root", "root", "study_english_database", sql)
    return HttpResponse(aaa)


